﻿@page "/tables/search"

<h3>@SearchLocalizer["Title"]</h3>

<h4>@SearchLocalizer["Desc"]</h4>

<Tips>
    <p>@((MarkupString)SearchLocalizer["SearchTableTips"].Value)</p>
</Tips>

<DemoBlock Title="@SearchLocalizer["SearchTableTitle"]" Introduction="@SearchLocalizer["SearchTableIntro"]" Name="SearchTable">
    <ul class="ul-demo mb-3">
        <li>@((MarkupString)SearchLocalizer["SearchTableLi1"].Value)</li>
        <li>@((MarkupString)SearchLocalizer["SearchTableLi2"].Value)</li>
        <li>@((MarkupString)SearchLocalizer["SearchTableLi3"].Value)</li>
    </ul>
    <Table TItem="Foo"
           IsPagination="true" PageItemsSource="@PageItemsSource"
           IsStriped="true" IsBordered="true"
           ShowToolbar="true" ShowSearch="true" IsMultipleSelect="true" ShowExtendButtons="true"
           AddModalTitle="@SearchLocalizer["AddModelTitle"]" EditModalTitle="@SearchLocalizer["EditModelTitle"]"
           SearchModel="@SearchModel" ShowEmpty="true" SearchMode="SearchMode.Top"
           OnQueryAsync="@OnSearchModelQueryAsync" OnResetSearchAsync="@OnResetSearchAsync"
           OnAddAsync="@OnAddAsync" OnSaveAsync="@OnSaveAsync" OnDeleteAsync="@OnDeleteAsync">
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Width="180" />
            <TableColumn @bind-Field="@context.Name" />
            <TableColumn @bind-Field="@context.Address" />
            <TableColumn @bind-Field="@context.Education" />
        </TableColumns>
        <SearchTemplate>
            <GroupBox Title="@SearchLocalizer["SearchTableGroupBoxText"]">
                <div class="row g-3 form-inline">
                    <div class="col-12 col-sm-6">
                        <BootstrapInput @bind-Value="@context.Name" PlaceHolder="@SearchLocalizer["NamePlaceholder"]" maxlength="50" ShowLabel="true" DisplayText="@Localizer[nameof(context.Name)]" />
                    </div>
                    <div class="col-12 col-sm-6">
                        <BootstrapInput @bind-Value="@context.Address" PlaceHolder="@SearchLocalizer["AddressPlaceholder"]" maxlength="500" ShowLabel="true" DisplayText="@Localizer[nameof(context.Address)]" />
                    </div>
                </div>
            </GroupBox>
        </SearchTemplate>
    </Table>
</DemoBlock>

<DemoBlock Title="@SearchLocalizer["AutoGenerateSearchTitle"]" Introduction="@SearchLocalizer["AutoGenerateSearchIntro"]" Name="AutoGenerateSearch">
    <p>@((MarkupString)SearchLocalizer["AutoGenerateSearchP"].Value)</p>
    <Tips>@((MarkupString)SearchLocalizer["AutoGenerateSearchTips"].Value)</Tips>
    <Pre>if (options.Searchs.Any())
{
    // @SearchLocalizer["AutoGenerateSearchCommnt"] FilterLogic.Or
    items = items.Where(options.Searchs.GetFilterFunc&lt;Foo&gt;(FilterLogic.Or));
}</Pre>
    <GroupBox Title="@SearchLocalizer["AutoGenerateSearchGroupBoxTitle"]" class="mb-2">
        <div class="row g-3 form-inline">
            <div class="col-12 col-sm-3">
                <Switch DisplayText="@SearchLocalizer["DisplayText1"]" ShowLabel="true" @bind-Value="SearchModeFlag" />
            </div>
            <div class="col-12 col-sm-3">
                <Switch DisplayText="@SearchLocalizer["DisplayText2"]" ShowLabel="true" @bind-Value="ShowSearchText" />
            </div>
            <div class="col-12 col-sm-3">
                <Switch DisplayText="@SearchLocalizer["DisplayText3"]" ShowLabel="true" @bind-Value="ShowResetButton" />
            </div>
            <div class="col-12 col-sm-3">
                <Switch DisplayText="@SearchLocalizer["DisplayText4"]" ShowLabel="true" @bind-Value="ShowSearchButton" IsDisabled="SearchModeFlag" />
            </div>
        </div>
    </GroupBox>
    <Table TItem="Foo"
           IsPagination="true" PageItemsSource="@PageItemsSource" SearchDialogShowMaximizeButton="true"
           IsStriped="true" IsBordered="true" SearchModel="@SearchModel" ShowSearch="true"
           SearchMode="SearchModeValue" ShowResetButton="ShowResetButton" ShowSearchButton="ShowSearchButton"
           ShowToolbar="true" IsMultipleSelect="true" ShowExtendButtons="true" ShowSearchText="ShowSearchText"
           AddModalTitle="@SearchLocalizer["AddModelTitle"]" EditModalTitle="@SearchLocalizer["EditModelTitle"]"
           OnQueryAsync="@OnQueryAsync" OnAddAsync="@OnAddAsync" OnSaveAsync="@OnSaveAsync" OnDeleteAsync="@OnDeleteAsync">
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Width="180" Filterable="true" />
            <TableColumn @bind-Field="@context.Name" Searchable="true" />
            <TableColumn @bind-Field="@context.Address" Searchable="true" />
            <TableColumn @bind-Field="@context.Education" Searchable="true" />
        </TableColumns>
    </Table>
</DemoBlock>

<DemoBlock Title="@SearchLocalizer["CustomColSearchTitle"]" Introduction="@SearchLocalizer["CustomColSearchIntro"]" Name="CustomColSearch">
    <p>@((MarkupString)SearchLocalizer["CustomColSearchP"].Value)</p>
    <p>@((MarkupString)SearchLocalizer["CustomColSearchP1"].Value)</p>
    <p>@((MarkupString)SearchLocalizer["CustomColSearchP2"].Value)</p>
    <p>@((MarkupString)SearchLocalizer["CustomColSearchP3"].Value)</p>
    <p>@((MarkupString)SearchLocalizer["CustomColSearchP4"].Value)</p>
    <Table TItem="Foo"
           IsPagination="true" PageItemsSource="@PageItemsSource"
           IsStriped="true" IsBordered="true" SearchModel="@SearchModel" ShowSearch="true" ShowSearchText="false"
           ShowToolbar="true" IsMultipleSelect="true" ShowExtendButtons="true" SearchDialogIsDraggable="true"
           AddModalTitle="@SearchLocalizer["AddModelTitle"]" EditModalTitle="@SearchLocalizer["EditModelTitle"]" SearchDialogShowMaximizeButton="true"
           OnQueryAsync="@OnQueryAsync" OnAddAsync="@OnAddAsync" OnSaveAsync="@OnSaveAsync" OnDeleteAsync="@OnDeleteAsync">
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Width="180" Filterable="true" />
            <TableColumn @bind-Field="@context.Name" Searchable="true">
                <SearchTemplate Context="model">
                    <div class="col-12 col-sm-6">
                        <Select Items="SearchItems" @bind-Value="@model!.Name" ShowLabel="true" DisplayText="姓名" />
                    </div>
                </SearchTemplate>
            </TableColumn>
            <TableColumn @bind-Field="@context.Address" Searchable="true" />
            <TableColumn @bind-Field="@context.Education" />
        </TableColumns>
    </Table>
</DemoBlock>

<DemoBlock Title="@SearchLocalizer["CustomerSearchModelTitle"]" Introduction="@SearchLocalizer["CustomerSearchModelIntro"]" Name="CustomerSearchModel">
    <p>@((MarkupString)SearchLocalizer["CustomerSearchModelP"].Value)</p>
    <Table TItem="Foo"
           IsPagination="true" PageItemsSource="@PageItemsSource" SearchMode="SearchMode.Top"
           IsStriped="true" IsBordered="true" CustomerSearchModel="@CustomerSearchModel" ShowSearch="true" ShowSearchText="true"
           ShowToolbar="true" IsMultipleSelect="true" ShowExtendButtons="true"
           OnQueryAsync="@OnQueryAsync" OnAddAsync="@OnAddAsync" OnSaveAsync="@OnSaveAsync" OnDeleteAsync="@OnDeleteAsync">
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Width="180" />
            <TableColumn @bind-Field="@context.Name" Searchable="true" />
            <TableColumn @bind-Field="@context.Address" Searchable="true" />
            <TableColumn @bind-Field="@context.Count" />
            <TableColumn @bind-Field="@context.Education" />
        </TableColumns>
        <CustomerSearchTemplate>
            @if (context is FooSearchModel model)
            {
                <FooSearch @bind-Value="@model" />
            }
        </CustomerSearchTemplate>
    </Table>
</DemoBlock>
